﻿//------------------------------------------------------------------------------
// ╭─────────────────────────────╮
// │ ╭─╮     ╭─╮              TM │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// │ │ │     │ │                 │                                           ☺  
// │ │ ╰───╮ │ │ ╭─────╮ ╭─────╮ │     Name:Wedn.Net 配置信息实体类      ♮ ♪ ♩
// │ │ ╭─╮ │ │ │ │ ╭─╮ │ │ ╭─╮ │ │                                    ♫ ♭      
// │ │ ╰─╯ │ │ │ │ ╰─╯ │ │ ╰─╯ │ │     Author:iceStone               ♬ ♪       
// │ └─────╯ └─╯ ╰─────╯ ╰───╮ │ │     Chinese:汪磊                              
// │                     ┌───╯ │ │                                              
// │                     ╰─────╯ │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// ╰─────────────────────────────╯                                              
//------------------------------------------------------------------------------
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Web;

namespace Wedn.Net.Common
{
    /// <summary>
    /// 配置信息实体类
    /// </summary>
    public static class Config
    {
        private static readonly NameValueCollection  Section = ConfigurationManager.GetSection("wednBlog")  as NameValueCollection;
        /// <summary>
        /// 程序Url
        /// </summary>
        public static string SiteUrl
        {
            get
            {
                //if (System.Web.HttpContext.Current.Request.Url.Port != 80)
                //{
                //    siteUrl = "http://" + System.Web.HttpContext.Current.Request.Url.Host + ":" + System.Web.HttpContext.Current.Request.Url.Port + SiteRoot;
                //}
                return "http://" + HttpContext.Current.Request.Url.Authority + SiteRoot;
            }
        }

        private static string _siteRoot;
        /// <summary>
        /// 程序相对根路径
        /// </summary>
        public static string SiteRoot
        {
            get
            {
                //避免装箱拆箱
                //string siteRoot = Application["SiteRoot"];
                if (string.IsNullOrEmpty(_siteRoot))
                {
                    _siteRoot = Section["SiteRoot"] ?? "/";
                }
                return _siteRoot;
            }
        }

        private static string _themeRoot;
        /// <summary>
        /// 主题皮肤所在根目录
        /// </summary>
        public static string ThemeRoot
        {
            get
            {
                if (string.IsNullOrEmpty(_themeRoot))
                {
                    _themeRoot = Section["ThemeRoot"] ?? "/Content/theme/";
                }
                return _themeRoot;
            }
        }

        private static string _uploadRoot;
        /// <summary>
        /// 文件上传根目录
        /// </summary>
        public static string UploadRoot
        {
            get
            {
                if (string.IsNullOrEmpty(_uploadRoot))
                {
                    _uploadRoot = Section["UploadRoot"] ?? "/Content/upload/";
                }
                return _uploadRoot;
            }
        }

        private static string _uploadMaxSize;
        /// <summary>
        /// 文件上传最大大小
        /// </summary>
        public static string UploadMaxSize
        {
            get
            {
                if (string.IsNullOrEmpty(_uploadMaxSize))
                {
                    _uploadMaxSize = Section["UploadMaxSize"] ?? "50";
                }
                return _uploadMaxSize;
            }
        }

        private static string[] _uploadAllowType;
        /// <summary>
        /// 文件上传允许类型
        /// </summary>
        public static string[] UploadAllowType
        {
            get
            {
                if (_uploadAllowType == null || _uploadAllowType.Length == 0)
                {
                    _uploadAllowType = (Section["UploadAllowType"] ?? "jpg,gif,png,rar,zip,doc,docx,pdf,txt,swf,wmv").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }
                return _uploadAllowType;
            }
        }

        private static string _sitePrefix;
        /// <summary>
        /// Cache、Session、Cookies 等应用程序变量名前缀
        /// </summary>
        public static string SitePrefix
        {
            get
            {
                if (string.IsNullOrEmpty(_sitePrefix))
                {
                    _sitePrefix = Section["SitePrefix"] ?? "WEDN_";
                }
                return _sitePrefix;
            }
        }

        private static string _encryptKey;
        /// <summary>
        /// 加密密钥
        /// </summary>
        public static string EncryptKey
        {
            get
            {
                if (string.IsNullOrEmpty(_encryptKey))
                {
                    _encryptKey = Section["EncryptKey"] ?? "iceStone";
                }
                return _encryptKey;
            }
        }

        private static string _tablePrefix;
        /// <summary>
        /// 数据库表前缀
        /// </summary>
        public static string TablePrefix
        {
            get
            {
                if (string.IsNullOrEmpty(_tablePrefix))
                {
                    _tablePrefix = Section["TablePrefix"] ?? "W_";
                }
                return _tablePrefix;
            }
        }

        private static string _statisticsTimespan;
        /// <summary>
        /// 统计任务执行线程时间间隔
        /// </summary>
        public static string StatisticsTimespan
        {
            get
            {
                if (string.IsNullOrEmpty(_statisticsTimespan))
                {
                    _statisticsTimespan = Section["StatisticsTimeSpan"] ?? "300000";
                }
                return _statisticsTimespan;
            }
        }

        private static string _bllAssembly;
        /// <summary>
        /// 业务逻辑层程序集名称
        /// </summary>
        public static string BllAssembly
        {
            get
            {
                if (string.IsNullOrEmpty(_bllAssembly))
                {
                    _bllAssembly = Section["BLLAssembly"] ?? "Wedn.Net.BLL";
                }
                return _bllAssembly;
            }
        }

        private static string _bllNamespace;
        /// <summary>
        /// 业务逻辑层管理类命名空间
        /// </summary>
        public static string BllNamespace
        {
            get
            {
                if (string.IsNullOrEmpty(_bllNamespace))
                {
                    _bllNamespace = Section["BllNamespace"] ?? "Wedn.Net.BLL";
                }
                return _bllNamespace;
            }
        }

        private static string _dalAssembly;
        /// <summary>
        /// 数据库操作类组件名
        /// </summary>
        public static string DALAssembly
        {
            get
            {
                if (string.IsNullOrEmpty(_dalAssembly))
                {
                    _dalAssembly = Section["DALAssembly"] ?? "Wedn.Net.DAL";
                }
                return _dalAssembly;
            }
        }

        private static string _dalNamespace;
        /// <summary>
        /// 数据库操作类命名空间
        /// </summary>
        public static string DALNamespace
        {
            get
            {
                if (string.IsNullOrEmpty(_dalNamespace))
                {
                    _dalNamespace = Section["DALNamespace"] ?? "Wedn.Net.DAL";
                }
                return _dalNamespace;
            }
        }

        private static string _connectionString;
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_connectionString))
                {
                    _connectionString = Section[Section["ConnStr"]];//ConfigurationManager.ConnectionStrings[Section["ConnStr"]].ConnectionString;
                }
                return _connectionString;
            }
        }
    }
}
